package com.yunsom.testdemo.multiple_thread.concurrent_tools;

import java.util.concurrent.TimeUnit;

/**
 * @author Xbao
 * @description
 * @date 2022/5/10 11:20
 */
class Counter {

  public synchronized void syncAdd() {
    String tName = Thread.currentThread().getName();
    System.out.println(tName + "加之前");
    for (int i = 0; i < 3; i++) {
      System.out.println(tName + "算到" + i);
      sleep(1);
    }
    System.out.println(tName + "加之后");
  }

  private void sleep(int count) {
    try {
      TimeUnit.SECONDS.sleep(count);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
}